package com.spx.core.wizards;

import org.apache.commons.lang.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.spx.core.types.Activity;

/**
 * The "New" wizard page allows setting the container for the new file as well
 * as the file name. The page will only accept file name without the extension
 * OR with the extension that matches the expected one (mpe).
 */

public class NewActionPage extends ModelWizardPage<Activity>
{

	private Text actionNameText;

	/**
	 * Constructor for SampleNewWizardPage.
	 * 
	 * @param pageName
	 */
	public NewActionPage()
	{
		super("wizardPage");
		setTitle("New Action Basic Details");
		setDescription("This wizard creates a Action.");

	}

	public String getContainerName()
	{
		return actionNameText.getText();
	}

	@Override
	public void setProperties(Activity activity)
	{
		activity.setName(this.actionNameText.getText());

	}

	@Override
	protected void createPageControl(Composite parent)
	{
		// final Composite container = new Composite(parent, SWT.NULL);
		final GridLayout layout = new GridLayout();
		parent.setLayout(layout);
		layout.numColumns = 2;
		layout.verticalSpacing = 9;
		final Label label = new Label(parent, SWT.NULL);
		label.setText("&Activity Name:");

		actionNameText = new Text(parent, SWT.BORDER | SWT.SINGLE);
		final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		actionNameText.setLayoutData(gd);

	}

	@Override
	protected boolean isValid()
	{
		boolean result = StringUtils.isNotBlank(actionNameText.getText());
		if (result == false)
		{
			setErrorMessage("Action Name  is Required");
		} else
		{
			setErrorMessage(null);
		}
		return result;
	}

}
